import { Assets, Graphics, GraphicsContext } from "pixi.js";
import { PixijsRender } from "../PixijsRender";
import { BaseEntity } from "./BaseEntity";
import { ViewState } from "./PixijsEntities";

export class SvgEntity extends BaseEntity {

    constructor(pixiRender: PixijsRender) {
        super(pixiRender);
        this.view = new Graphics();
        //this.__render.viewRoot.addChild(this.view);
        this.className = this.constructor.name
    }

    loadAssets(){
        this.__render.world.update(this, "viewState", ViewState.Loading)
        Assets.load({
            src: this.url,
            data: {
                parseAsGraphicsContext: true,
            },
        }).then((svg:GraphicsContext) => {
            if (this.viewState === ViewState.Loading) {
                (this.view as Graphics).context = svg;
                this.__render.world.update(this, "viewState", ViewState.Showing)
                console.log(this.view)
            }
            this.__render.viewDirty = true;
        })
    }

    unloadAssets() {
        super.unloadAssets();
    }
}